package com.roadmap.struts.action.admin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.roadmap.biz.message.NoticeManager;
import com.roadmap.client.module.IManager;
import com.roadmap.client.sns.VisitorManager;
import com.roadmap.struts.action.ActionConst;
import com.roadmap.struts.action.RdcAction;

public class GoHomeAction extends RdcAction {
	public GoHomeAction() {
		super("gohome");
	}

	@Override
	public ActionForward performAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String ownerId = getUIDFromSession(request);
		IManager mgr = new VisitorManager(ownerId);
		List visitors = mgr.getEntitiesOfParent();
		if (visitors != null && !visitors.isEmpty()) {
			request.setAttribute("visitors", visitors);
		}
		
		// load the latest activities information
		NoticeManager noticeMgr = new NoticeManager(mgr.getOwner());
		List activities = null;
		String currentAction = request.getParameter(ActionConst.Method_Symbol);
		// currentAction only has two options 'friend' and 'me'
		if(currentAction == null || !currentAction.equalsIgnoreCase("me")) {
			activities = noticeMgr.getFriendActivities();
		}
		else {
			activities = noticeMgr.getOwnActivities();
		}
		if(activities != null && !activities.isEmpty()) {
			request.setAttribute("activities", activities);
		}
		
		return mapping.findForward("gohome");
	}

	@Override
	public boolean isFormSubmitted(HttpServletRequest request) throws Exception {
		return false;
	}

}
